//
//  ViewController.swift
//  MagoT
//
//  Created by mac on 2023/12/22.
//

import UIKit
import AuthenticationServices
import RxSwift

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        if #available(iOS 13.0, *) {
            let appleLoginBtn = ASAuthorizationAppleIDButton()
            appleLoginBtn.addTarget(self, action: #selector(handleAppleLoginButtonPress(sender:)), for: .touchUpInside)
            appleLoginBtn.frame = CGRect(x: 50, y: 200, width: 200, height: 50)
            self.view.addSubview(appleLoginBtn)
        } else {
            // Fallback on earlier versions
        }
        
        let observable = Observable<Int>.create { observer in
            
            observer.onNext(1)
            observer.onNext(2)
            observer.onNext(3)
            return Disposables.create()
        }
        
        let sharedObservable = observable.share(replay: 1)
        
        let subscription1 = sharedObservable.subscribe { value in
            print("Subscription 1 - Received value: \(value)")
        }
        
        let subscription2 = sharedObservable.subscribe(onNext: { value in
            print("Subscription 2 - Received value: \(value)")
        })
        
        
    }
    
    @objc func handleAppleLoginButtonPress(sender: UIButton) {
        AppleLoginManager.shared.handleAuthorizationAppleIDLogin { (isSuccess, message) in
        }
    }
}

